**file to replicate results in "Terminating Alliances: Why Do States Abrogate Agreements?" by Brett Ashley Leeds and Burcu Savun
**created with stata 9.2

**Stochastically Independent Semi-parametric Competing Risks Model of Alliance Termination
set mem 128m
set more off
set matsize 400
use "LeedsSavunJOP2007.dta", clear

** COX Proportional Hazards Model of Alliance Termination by Violation

sort atopidphase obyear
stset dur, id(atopidphase) failure(violate)
stcox capchangeeither regchangeeither chTEeither30lt alform demever asymmetry  nomicoop treaty milinst, robust efron cluster(atopidphase) nohr

** Diagnostics and Sensitivity Tests 
* 1. Proportionality Assumption:
stcox capchangeeither regchangeeither chTEeither30lt alform demever asymmetry  nomicoop treaty   milinst, robust efron sch(sch*) sca(sca*) mg(mgresid)
stphtest
lowess sca1 dur, bw(.9) s(o)
lowess sca2 dur, bw(.9) s(o)
lowess sca3 dur, bw(.9) s(o)
lowess sca4 dur, bw(.9) s(o)
lowess sca5 dur, bw(.9) s(o)
lowess sca6 dur, bw(.9) s(o)
lowess sca7 dur, bw(.9) s(o)
lowess sca8 dur, bw(.9) s(o)
lowess sca9 dur, bw(.9) s(o)

*2. Unobserved Unit Level Heterogeneity: Cox Model with gamma distributed frailties
*stcox  capchangeeither regchangeeither chTEeither30lt alform demever asymmetry  nomicoop treaty   milinst,  efron nohr sh(atopidphase) frailty(gamma)
drop mgresid sch1 sch2 sch3 sch4 sch5 sch6 sch7 sch8 sch9  sca1 sca2 sca3 sca4 sca5 sca6 sca7 sca8 sca9 

*3. Without the longest (non-censored) alliance (ATOP2170)
drop if atopid==2170
stset dur, id(atopidphase) failure(violate)
stcox capchangeeither regchangeeither chTEeither30lt alform demever asymmetry  nomicoop treaty milinst, robust efron nohr cluster(atopidphase)
** add 2170 back in
use "LeedsSavunJOP2007.dta", clear

*4. including control variable for whether alliance was invoked by war
stset dur, id(atopidphase) failure(violate)
stcox capchangeeither regchangeeither chTEeither30lt alform invoked demever asymmetry  nomicoop treaty milinst, robust efron nohr cluster(atopidphase)

* 5. Weibull Model of Violation
stset dur, id(atopidphase) failure(violate)
streg capchangeeither regchangeeither chTEeither30lt alform demever asymmetry  nomicoop treaty  milinst, robust distribution(weibull) cluster (atopidphase) nohr

*6. Sensitivity Testing
*Different thresholds for change in power, regime and threat

*cap threshold 5
stset dur, id(atopidphase) failure(violate)
stcox  capchangeeither5 regchangeeither chTEeither30lt alform demever asymmetry  nomicoop treaty   milinst, robust efron nohr cluster (atopidphase)

*cap threshold 20
stset dur, id(atopidphase) failure(violate)
stcox  capchangeeither20 regchangeeither chTEeither30lt alform demever asymmetry  nomicoop treaty milinst, robust efron nohr cluster (atopidphase)

*reg threshold 1
stset dur, id(atopidphase) failure(violate)
stcox  capchangeeither regchangeeither1unit chTEeither30lt alform demever asymmetry  nomicoop treaty  milinst, robust efron nohr cluster (atopidphase)

*reg threshold 3
stset dur, id(atopidphase) failure(violate)
stcox  capchangeeither regchangeeither3 chTEeither30lt alform demever asymmetry  nomicoop treaty   milinst, robust efron nohr cluster (atopidphase)

*TE threshold 10
stset dur, id(atopidphase) failure(violate)
stcox capchangeeither regchangeeither chTEeither10lt alform demever asymmetry  nomicoop treaty  milinst, robust efron nohr cluster(atopidphase)

*TE threshold 20
stset dur, id(atopidphase) failure(violate)
stcox capchangeeither regchangeeither chTEeither20lt alform demever asymmetry  nomicoop treaty  milinst, robust efron nohr cluster(atopidphase)

*TE threshold 40
stset dur, id(atopidphase) failure(violate)
stcox capchangeeither regchangeeither chTEeither40lt alform demever asymmetry  nomicoop treaty  milinst, robust efron nohr cluster(atopidphase)

*TE threshold 50
stset dur, id(atopidphase) failure(violate)
stcox capchangeeither regchangeeither chTEeither50lt alform demever asymmetry  nomicoop treaty milinst, robust efron nohr cluster(atopidphase)

*7. Cox Proportional Hazard Model of Renegotiation
sort atopidphase obyear
stset dur, id(atopidphase) failure(renegstwe)
stcox capchangeeither regchangeeither chTEeither30lt alform demever asymmetry  nomicoop treaty  milinst, robust efron cluster(atopidphase) nohr

*8. Cox Proportional Hazard Model of Fulfillment
stset dur, id(atopidphase) failure(fulfill)
stcox capchangeeither regchangeeither chTEeither30lt alform demever asymmetry  nomicoop treaty milinst, robust efron nohr cluster(atopidphase)
